package com.delayqueue.master.netty.handler;

import com.delayqueue.common.netty.Address;
import com.delayqueue.common.netty.NettyUtil;
import com.delayqueue.master.cache.NodeCacheFactory;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ConnectInboundHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        Address address = NettyUtil.getRemoteAddress(ctx);
        log.info("已下线：{}", address);
        NodeCacheFactory.core.delete(address.getIp(), address.getPort());
    }
}
